package com.yycx.base.provider.handler;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.constants.CommonConstants;
import com.yycx.common.mybatis.interceptor.SaveInterceptor;
import com.yycx.common.mybatis.query.CriteriaSave;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.utils.StringUtils;
import com.yycx.module.admin.client.constants.BaseConstants;
import com.yycx.module.admin.client.entity.BaseRole;
import com.yycx.module.admin.client.entity.BaseUser;
import com.yycx.module.admin.provider.service.BaseAccountService;
import com.yycx.module.system.client.entity.SysCompany;
import com.yycx.module.system.client.entity.SysDept;
import com.yycx.module.system.provider.service.SysCompanyService;
import com.yycx.module.system.provider.service.SysDeptService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 后台角色添加扩展
 *
 * @author zyf
 */
@Component
@AllArgsConstructor
public class BaseRoleAddHandler implements SaveInterceptor<BaseRole> {

    private final SysCompanyService companyService;

    @Override
    public void prepare(CriteriaSave cs, EntityMap params, BaseRole baseRole) {
        Long companyId = FlymeUtils.isEmpty(baseRole.getCompanyId()) ? OpenHelper.getCompanyId() : baseRole.getCompanyId();
        if (FlymeUtils.isNotEmpty(companyId)) {
            SysCompany company = companyService.getById(companyId);
            if (FlymeUtils.isNotEmpty(company)) {
                baseRole.setOrganizationId(company.getOrganizationId());
            }
            baseRole.setCompanyId(companyId);
        }
    }

}
